﻿
@{
    ViewBag.Title = "Detail";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>
    .btn-group {
        right: 50px;
    }
    .panel-primary > .panel-heading {
        background-color: #fff;
        border-color: #fff;
    }
</style>
<form id="form1">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <span class="h5">供应商信息</span>
        </div>
        <table class="table table-border table-hover">
            <tr>
                <td>
                    <table class="form">
                        <tr>
                            <th class="formTitle">供应商名称：</th>
                            <td class="formValue">
                                <input id="name" name="name" type="text" class="form-control" placeholder="请录入供应商名称" />
                            </td>

                            <th class="formTitle">公司规模：</th>
                            <td class="formValue">
                                <select id="company_size" name="company_size" style="width:92%" class="form-control required">
                                    <option value="50人以下">50人以下</option>
                                    <option value="50-100人">50-100人</option>
                                    <option value="100-500人">100-500人</option>
                                    <option value="500人以上">500人以上</option>
                                </select>
                            </td>

                            <th class="formTitle">城市：</th>
                            <td class="formValue">
                                <select id="city_id" name="city_id" style="width:92%" class="form-control required">
                                    <option value="">==请录入城市==</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">公司负责人：</th>
                            <td class="formValue">
                                <input id="company_owner" name="company_owner" type="text" class="form-control" placeholder="请录入公司负责人" />
                            </td>

                            <th class="formTitle">行业领域：</th>
                            <td class="formValue">
                                <input id="industry_field" name="industry_field" type="text" class="form-control" placeholder="请录入行业领域" />
                            </td>

                            <th class="formTitle">业务范围：</th>
                            <td class="formValue">
                                <select id="business_scope" name="business_scope" style="width:92%" class="form-control required">
                                    <option value="场地租赁">场地租赁</option>
                                    <option value="灯光音响">灯光音响</option>
                                    <option value="视频投影">视频投影</option>
                                    <option value="摄影摄像">摄影摄像</option>

                                    <option value="车辆服务">车辆服务</option>
                                    <option value="设计策划">设计策划</option>
                                    <option value="礼仪服务">礼仪服务</option>
                                    <option value="外烩餐饮">外烩餐饮</option>

                                    <option value="演员节目">演员节目</option>
                                    <option value="鲜花装饰">鲜花装饰</option>
                                    <option value="礼品定制">礼品定制</option>
                                    <option value="印刷物料">印刷物料</option>

                                    <option value="保洁安保">保洁安保</option>
                                    <option value="活动报批">活动报批</option>
                                    <option value="其他">其他</option>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <th class="formTitle">业务性质：</th>
                            <td class="formValue">
                                <input id="business_nature" name="business_nature" type="text" class="form-control" placeholder="请录入业务性质" />
                            </td>
                            <th class="formTitle">公司简介：</th>
                            <td class="formValue">
                                <textarea id="company_profile" style="height:70px; width: 94%;" name="company_profile" type="text" class="form-control" placeholder="请录入公司简介"></textarea>
                            </td>
                            <th class="formTitle">资质：</th>
                            <td class="formValue">
                                <input id="aptitude" name="aptitude" type="text" class="form-control" placeholder="请录入" />
                            </td>
                        </tr>

                        <tr>
                            <th class="formTitle">发票类型：</th>
                            <td class="formValue">
                                <select id="F_InvoiceType" name="F_InvoiceType" style="width:92%" class="form-control required">
                                    <option value="">==请录入发票类型==</option>
                                    <option value="1">增值税专用发票</option>
                                    <option value="2">增值税普通发票</option>
                                </select>
                            </td>
                            <th class="formTitle">银行账户名称：</th>
                            <td class="formValue">
                                <input id="F_BankName" name="F_BankName" type="text" class="form-control" placeholder="请录入银行账户名称" />
                            </td>
                            <th class="formTitle">银行账号：</th>
                            <td class="formValue">
                                <input id="F_BankAcount" name="F_BankAcount" type="text" class="form-control" placeholder="请录入银行账号" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">开户行名称（具体到支行）：</th>
                            <td class="formValue">
                                <input id="F_OpenBankName" name="F_OpenBankName" type="text" class="form-control" placeholder="请录入开户行名称（具体到支行）" />
                            </td>
                        </tr>


                        <tr>
                            <th class="formTitle">营业执照：</th>
                            <td class="">
                                <img style="width:400px;height:300px" src="" id="BL" />
                                <input id="BL_" accept="image/*" style="width: 73%;display: inline-block;" type="file" name="filesf" />
                            </td>
                            <th class="formTitle">名片：</th>
                            <td class="">
                                <img style="width:400px;height:300px" src="" id="Vcard" />
                                <input id="Vcard_" accept="image/*" style="width: 73%;display: inline-block;" type="file" name="filesf" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle"></th>
                            <td class="formValue"></td>
                            <th class="formTitle"></th>
                            <td class="formValue"></td>
                            <th class="formTitle"></th>
                            <td class="formValue">
                                <button id="btn_save" name="btn_save_order_request" class="btn btn-primary btn-sm" type="button">修改并保存</button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <div class="panel-heading">
            <span class="h5">联系人信息</span>
        </div>
        <div class="topPanel">
            <div class="toolbar">
                <div class="btn-group">
                    <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
                  
                </div>
                <div class="btn-group">
                    <a id="btn_add" class="btn btn-primary dropdown-text"><i class="fa fa-eraser"></i>添加联系人</a>
                </div>
                <div class="operate" style="left: -100.1%;">
                    <ul class="nav nav-pills">
                        <li class="first">已选中<span>1</span>项</li>
                        <li><a id="NF-edit" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改联系人</a></li>
                        <li><a id="NF-delete" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除联系人</a></li>
                    </ul>
                    <a href="javascript:;" class="close"></a>
                </div>
            </div>
        </div>
        <table class="table table-border table-hover">
            <tr>
                <td></td>
            </tr>
            <tr>
                <td>
                    <div class="gridPanel">
                        <table id="gridList" style="width:100%;"></table>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</form>
<script>$('.toolbar').authorizeButton()</script>
<script>
    var h = "http://storage.yunspace.com.cn/";
    $(function () {
        getItemList()
        $.ajax({
            url: "/SiteManage/Supplier/GetDetailJson",
            dataType: "json",
            async: false,
            success: function (data) {
                $("#form1").formSerialize(data);
                $('#Vcard').attr('src', h + data.Vcard);
                $('#BL').attr('src', h + data.BusinessLicense);
            }
        });
        InitGrid();
        $("#btn_save").click(function () {
            //if (!$('#form1').formValid()) {
            //    return false;
            //}
            var name = $.trim($('#name').val());
            var company_size = $.trim($('#company_size').val());
            var company_owner = $.trim($('#company_owner').val());
            var industry_field = $.trim($('#industry_field').val());
            var business_scope = $.trim($('#business_scope').val());
            var business_nature = $.trim($('#business_nature').val());
            var company_profile = $.trim($("#company_profile").val());
            var aptitude = $.trim($('#aptitude').val());
            if (name.length > 100) {
                alert('供应商名称限制100字');
                return false;
            }
            if (company_size.length > 100) {
                alert('公司规模限制100字');
                return false;
            }
            if (company_owner.length > 100) {
                alert('公司负责人限制100字');
                return false;
            }
            if (industry_field.length > 100) {
                alert('行业领域限制100字');
                return false;
            }
            if (business_scope.length > 100) {
                alert('业务范围限制100字');
                return false;
            }
            if (business_nature.length > 100) {
                alert('业务性质限制100字');
                return false;
            }
                
            if (company_profile.length > 100) {
                alert('公司简介限制100字');
                return false;
            }
                
            if (aptitude.length > 100) {
                alert('资质限制100字');
                return false;
            }
                
            $.modalConfirm('您确认要修改此供应商的信息吗？', function (flag, index) {
                if (flag) {

                    uploadSend('BL_', 'BusinessLicense')
                    uploadSend('Vcard_', 'Vcard');
                    var param = $("#form1").formSerialize();
                    param.BusinessLicense = BLfiles.F_path;
                    param.Vcard = VCardfiles.F_path;
                    //console.log(param);
                    $.submitForm({
                        url: "/SiteManage/Supplier/SubmitSupplierInfo",
                        param: param,
                        success: function (data) {
                            location.reload();
                            $.modalConfirmClose(index);
                           
                        }
                    });

                }
            });
        });
        $('#btn_add').click(function () {
            $.modalOpen({
                id: "AddContact",
                title: "添加联系人",
                url: "/SiteManage/Supplier/Contact?keyValue=",
                width: "700px",
                height: "380px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        });
    });

    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "UpContact",
            title: "修改联系人",
            url: "/SiteManage/Supplier/Contact?keyValue=" + keyValue,
            width: "700px",
            height: "380px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_delete() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.deleteForm({
            url: "/SiteManage/Supplier/DeleteContactForm",
            param: { keyValue: $("#gridList").jqGridRowValue().F_Id },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }

    function InitGrid() {
        var $gridList = $("#gridList");
        var Role = [{ "id": "2002", "name": "场地联络人" }, { "id": "2001", "name": "场地管理员" }];
        $gridList.dataGrid({
            url: "/SiteManage/Supplier/GetSupplierGridJson",
            height: $(window).height() - 476,
            colModel: [
                { label: 'F_Id', name: 'F_Id', hidden: true },
                {
                    label: '联系人名称', name: 'ContactName', width: 200, align: 'center', sortable: false
                },
                {
                    label: '手机', name: 'Phone', width: 200, align: 'left', sortable: false
                },
                {
                    label: '电话', name: 'Mobile', width: 200, align: 'left', sortable: false
                },
                {
                    label: '角色', name: 'RoleId', width: 200, align: 'left', sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < Role.length; i++) {
                            if (Role[i].id == cellvalue)
                                return Role[i].name;
                        }
                        return "";
                    }
                },
                {
                    label: '邮箱', name: 'Email', width: 200, align: 'center', sortable: false
                }
            ],
            pager: "#gridPager",
            sortname: 'F_LastModifyTime',
            viewrecords: true,
            ondblClickRow: function (rowid, iRow, iCol, e) {
                var rowobj = $gridList.getRowData(rowid);
                vm.sendsite.bindSiteDetail(rowobj["F_SiteId"]);
            }
        });
    }

    function getItemList() {
        $.ajax({
            url: "/SiteManage/Site/GetItemListJson",
            dataType: "json",
            async: false,
            success: function (data) {
                initControl(data)
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
    }

    function initControl(ItemList) {
        var City = ItemList.City;
        for (var i = 0; i < City.length; i++) {
            $("#city_id").append("<option value='" + City[i].F_ItemCode + "'>" + City[i].F_ItemName + "</option>");
        }
        var SiteState = ItemList.SiteState;

        $("#city_id").bindSelect();
        $('#city_id').select2({
            placeholder: '==请选择城市=='
        });

        $('#company_size').bindSelect();

        $('#business_scope').bindSelect();
        $('#business_scope').select2({
            multiple: true
        });

        $('#F_InvoiceType').bindSelect();
        $('#F_InvoiceType').select2({
            placeholder: '==请录入发票类型=='
        });
    }

    var VCardfiles = {}, BLfiles = {};
    var myDate = new Date();
    var mytime = myDate.getFullYear().toString() + myDate.getMonth().toString() + myDate.getDate().toString();
    function uploadSend(actionId, type) {
        cvalue = "";
        bigvlue = "";
        imgWidthType = "";
        var big = 30;

        var data = new FormData();
        var item = document.getElementById(actionId);
        if (item != null && item.files.length > 0) {
            var files = item.files;
            var fid = files.length;
            bigvlue = "";
            for (var i = 0; i < files.length; i++) {
                var file = item.files[i];
                fileSize = file.size;
                fileSize = Math.round(fileSize / 1024 * 100) / 100; //kb
                if (fileSize > 30720) {
                    bigvlue += file.name + ' ';
                } else {
                    data.append(file.name, file);
                    if (type == "Vcard") {
                        VCardfiles = {
                            name: file.name,
                            F_Id: fid + i,
                            tag: '',
                            is_cover: false,
                            photoable_type: type,
                            F_path: 'uploads/files/path/' + mytime + '/' + file.name
                        }
                    }
                    else {
                        BLfiles = {
                            name: file.name,
                            F_Id: fid + i,
                            tag: '',
                            is_cover: false,
                            photoable_type: type,
                            F_path: 'uploads/files/path/' + mytime + '/' + file.name
                        };
                    }
                }
            }

            xhr = new XMLHttpRequest();
            xhr.onload = function () {

                //$.modalAlert("上传成功！", "success");
            };
            xhr.onerror = function (err) {
                console.error(err);

            };
            xhr.open('post', '/SiteManage/Site/UploadPathFiles?sitename=' + mytime, true);
            xhr.send(data);
        }
        else {
            $.modalAlert("请先选择您要上传的文件！", "warning");
        }
    }
</script>

